public class The_maximum_number_of_consecutive_ones {
    class Solution {
        public int longestOnes(int[] nums, int k) {
            int left =0;
            int right =0;
            int l = 0;
            int tar = 0;
            for( ;right<nums.length;right++){
                if(nums[right]==0){
                    l++;
                }
                while(l>k){
                    if(nums[left]>0){
                        left++;
                    }
                    else{
                        left++;
                        l--;
                    }
                }
                tar=Math.max(tar,right-left+1);

            }
            return tar;
        }
    }
}
